package J5_22;

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

public class test {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        String n = in.next();
        String[] strs = n.split("-");
        int a1 = Integer.parseInt(strs[0]);
        for (int i = 0; i < strs[1].length(); i++) {
            a1 += (strs[1].charAt(i) - '0') * (i + 2);
        }
        for (int i = 0; i < strs[2].length(); i++) {
            a1 += (strs[2].charAt(i) - '0') * (i + 5);
        }
        String res = a1 % 11 + "";
        if (res.equals("10")) {
            res = "X";
        }
        if (res.equals(strs[3])) {
            System.out.println("Right");
        } else {
            System.out.println(n.substring(0, n.length() - 1) + res);
        }
    }

    static int[] x = {0,0,1,-1};
    static int[] y = {1,-1,0,0};
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt();
        char[][] ch = new char[n + 2][m + 2];
        int sX = 0, sY = 0;
        for (int i = 1; i < n + 1; i++) {
            char[] cur = in.next().toCharArray();
            for (int j = 1; j < m + 1; j++) {
                ch[i][j] = cur[j-1];
                if (ch[i][j] == 'k') {
                    sX = i;
                    sY = j;
                }
            }
        }
        for (int i = 0; i <= n + 1; i++) {
            ch[i][0] = '*';
            ch[i][m + 1] = '*';
        }
        for (int j = 0; j <= m + 1; j++) {
            ch[0][j] = '*';
            ch[n + 1][j] = '*';
        }
        Queue<int[]> queue = new ArrayDeque<>();
        queue.add(new int[]{sX, sY});
        boolean[][] vis = new boolean[n + 1][m + 1];
        vis[sX][sY] = true;
        int step = 0, count = 0, res = -1;
        while (!queue.isEmpty()) {
            int s = queue.size();
            step++;
            for (int k = 0; k < s; k++) {
                int[] cur = queue.poll();
                for (int i = 0; i < 4; i++) {
                    int x1 = cur[0] + x[i];
                    int y1 = cur[1] + y[i];
                    if (ch[x1][y1] == '.' && !vis[x1][y1]) {
                        queue.add(new int[]{x1, y1});
                        vis[x1][y1] = true;
                    } else if (ch[x1][y1] == 'e' && !vis[x1][y1]) {
                        count++;
                        vis[x1][y1] = true;
                        if (res == -1) {
                            res = step;
                        }
                    }
                }
            }
        }
        if (count == 0) {
            System.out.println(-1);
        } else {
            System.out.println(count + " " + res);
        }
    }


}
